package com.mozq.boot.swagger01.demo;

import com.mozq.boot.swagger01.config.MozqConfig;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.File;

@RestController
public class DemoController {
    /**
     * springboot中"user.dir"属性得到的是jar包执行时，jar包所在的目录的磁盘路径，末尾不带文件分隔符。
     * 如：jar包被放在"D:\Adobe"，则 System.getProperty("user.dir")得到的磁盘路径就是"D:\Adobe"
     * @return
     */
    @RequestMapping("/userDir")
    public String userDir(){
        String userDir = System.getProperty(MozqConfig.USER_DIR) + File.separator;
        return userDir;
    }

    @RequestMapping("/realPath")
    public String realPath(HttpServletRequest request){
        String realPath = request.getServletContext().getRealPath("");
        return realPath;
    }
}
